package com.hgm.travelapp.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.Window
import android.view.WindowManager
import com.hgm.travelapp.R
import com.hgm.travelapp.databinding.ActivityDetailsBinding
import com.hgm.travelapp.utils.ToastUtil

class DetailsActivity : AppCompatActivity(), View.OnClickListener {

    private val mBinding: ActivityDetailsBinding by lazy {
        ActivityDetailsBinding.inflate(layoutInflater)
    }

    private var isLike = false//不喜欢

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //隐藏状态栏
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
        setContentView(mBinding.root)

        initView()
    }

    private fun initView() {
        mBinding.apply {
            back.setOnClickListener(this@DetailsActivity)
            ivLike.setOnClickListener(this@DetailsActivity)
        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.back -> this.finish()
            R.id.iv_like -> {
                if (isLike) {
                    mBinding.ivLike.isSelected = false//取消点赞
                    isLike=false
                } else {
                    mBinding.ivLike.isSelected = true//点赞
                    isLike=true
                    ToastUtil.toastShort(this,"点赞成功")
                }
            }
        }
    }

}